package com.example.ormsqlsplicingframe1.warpper;

import com.example.ormsqlsplicingframe1.session.SessionUtil;
import com.example.ormsqlsplicingframe1.sql.ConditionSql;
import com.example.ormsqlsplicingframe1.sql.impl.DeleteImpl;

import java.util.function.Consumer;

public class DeleteSqlWrapper {


    private DeleteImpl delete = new DeleteImpl();


    public DeleteSqlWrapper title(String name){
        delete.table(name);
        return this;
    }

    public void execute(){
        if (SessionUtil.getSession().delete(delete) ==0) throw new IllegalStateException("删除失败");
    }

    private ConditionSql where(){
        return delete.where();
    }

    public DeleteSqlWrapper where(Consumer<ConditionSql> condition){
        condition.accept(where());
        return this;
    }

    private static DeleteSqlWrapper  deleteSqlWrapper= null;

    public synchronized static DeleteSqlWrapper newInstance() {

        if (deleteSqlWrapper==null){
            return new DeleteSqlWrapper();
        }
        return deleteSqlWrapper;

    }

}
